var mysql = require('mysql');

var pool = mysql.createPool({
    connectionLimit: 10,
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'mydatabase'
});

function queryPromise(sql, values) {
    return new Promise((resolve, reject) => {
        pool.getConnection((err, connection) => {
            if (err) throw err;
            connection.query(sql, values, function (err, results, fields) {
                if (err) {
                    reject(err);
                } else {
                    resolve(results);
                }
                connection.release();
            });
        });
    });
}

exports.queryPromise = queryPromise;